package com.bawei.contentresolver2;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ContentResolver;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private Uri uri;
    private ContentResolver contentResolver;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //通过contentResovler查询数据
        uri = Uri.parse("content://com.bawei.2010");
        contentResolver = getContentResolver();
        //删除一条数据
        delete();
    }

    private void delete() {
        int num = contentResolver.delete(uri, "_id = ?", new String[]{"7"});
        contentResolver.notifyChange(uri,null);
        Toast.makeText(this, "删除数据"+num, Toast.LENGTH_SHORT).show();
    }
}